<?php

namespace app\admin\model;

use app\common\model\BaseModel;


class SubjectExam extends BaseModel
{

    

    

    // 表名
    protected $name = 'subject_exam';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'ceatetime_text'
    ];


    public function getList($where, $size = 12, $field = '*', $order = 'id desc')
    {
        $list = $this->where(function ($query) use ($where) {

        })
            ->with([])
            ->field($field)
            ->order($order)
            ->paginate($size);
        //$list->each(function ($item) {
        //});
        return $list->toArray();

    }

    /**
    * @param Model $row
    */
    protected static function onAfterInsert($row){
//        $pk = $row->getPk();
//        $row->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
    }

    

    public function getCeatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ceatetime']) ? $data['ceatetime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCeatetimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function factor(){
        return $this->belongsTo('Factor', 'factor_id','id' );
    }

    public function subject(){
        return $this->belongsTo('Subject', 'subject_id','id' );
    }


}
